package com.qin.malldiscount.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qin.mall.common.api.CommonResult;
import com.qin.mall.common.api.MyBatisPlusPage;
import com.qin.malldiscount.domain.CmsSubject;
import com.qin.malldiscount.service.CmsSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品专题管理
 * @author Leisure
 * create 2022 2022/11/24 12:15
 **/
@RestController
@RequestMapping("/productSubject")
public class CmsSubjectController {

    @Autowired
    private CmsSubjectService subjectService;

    /**
     * 获取全部商品专题
     */
    @GetMapping("/listAll")
    @ResponseBody
    public CommonResult<List<CmsSubject>> listAll() {
        List<CmsSubject> subjectList = subjectService.listAll();
        return CommonResult.success(subjectList);
    }

    /**
     * 根据专题名称分页获取专题
     */
    @GetMapping("/list")
    @ResponseBody
    public CommonResult<MyBatisPlusPage<CmsSubject>> getList(@RequestParam(value = "keyword", required = false) String keyword,
                                                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        Page<CmsSubject> subjectList = subjectService.getList(keyword, pageNum, pageSize);
        return CommonResult.success(MyBatisPlusPage.mpPage(subjectList));
    }
}
